<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<script type="text/javascript" src="<%=basePath%>Js/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mycss/bootstrap.min.css" />

        <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
		<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
		<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<head>
<meta charset="UTF-8">
</head>
<script type="text/javascript">

//通过房间号查询房间动态
function selectRoomByNumber(){
	var roomNumber = $("#roomNumber").val();
	if (!(/(^[0-9]*[1-9][0-9]*$)/.test(roomNumber))){
		alert("你的输入带有字符");
	}else{
		$.ajax({
			type:"post",
			url:"selectRoomByNumber.do",
			data:{
				"roomNumber":roomNumber,
			},
			success:function(result){
				stus = JSON.parse(result)
				for(var i = 0; i < stus.length; i++ ){
					var stu = "";
					stu += "<tr><th>房间号</th><th>楼层</th><th>价格</th><th>房型</th> <th>状态</th><th>容纳人数</th><th>备注</th><th>操作</th></tr>";
					stu += "<tr><td>"+stus[i].roomnum+"</td><td>"+stus[i].floor+"</td><td>"+stus[i].price+"</td>";
					stu += "<td>"+stus[i].type+"</td> <td>"+stus[i].status+"</td><td>"+stus[i].quantity+"</td><td>"+stus[i].remark+"</td>";
					stu += "<td><button type='button' onclick='checkoutInf("+stus[i].roomnum+")' class='btn btn-success' data-toggle='modal' data-target='#checkoutModal'>退房</button></td>"
					stu += "</tr>"
					
				}
				$("#page1").remove();
				$("#roomTable").empty();
				$("#roomTable").html(stu);
			},
			error:function(){
				
			}
		})
	}
}

//通过楼层、房间动态、房型条件查询房间信息
function selectRoomByother(){
	
	var floor = $("#floor").find("option:selected").text();
	var state = "使用中";
	var houseType = $("#houseType").find("option:selected").text();
	
	window.location.href="selectRoomByother2.do?floor="+floor+"&state="+state+"&houseType="+houseType;

}

//获取房间信息————模态框
function checkoutInf(roomNumber){
	
	var vipnumber;
	$.ajax({
		type:"post",
		url:"selectRoomByNumber.do",
		data:{
			"roomNumber":roomNumber,
		},
		success:function(result){
			
			stus = JSON.parse(result)
		
			var stu = "";
			for(var i = 0; i < stus.length; i++ ){
				
				stu +="<tr>";
				stu +="<td>房间号</td><td><input type='text' class='form-control' id='roomNumber2' value='"+stus[i].roomnum+"' readonly='readonly'></td>";
				stu +="<td>房型</td><td><input type='text' class='form-control' id='roomType' value='"+stus[i].type+"' readonly='readonly'></td>";
				stu +="<td>价格</td><td><input type='text' class='form-control' id='roomPrice' value='"+stus[i].price+"' readonly='readonly'></td>";
				stu +="</tr>";
				stu +="<tr>";
				stu +="<td>入住人数</td><td><input type='text' class='form-control' id='roomPeople' value='"+stus[i].reserved3+"' readonly='readonly'></td>";
				stu +="</tr>";
				
				vipnumber = stus[i].reserved2;
			}
			
			$("#roomTable2").html(stu);
			VipInf(vipnumber);

		},
		error:function(){
			alert("系统故障")
		}
	})
}

//非会员获取房间信息---模态框
function nonmemberCheckoutInf(roomNumber){
	
	var orderNumber;
	$.ajax({
		type:"post",
		url:"selectRoomByNumber.do",
		data:{
			"roomNumber":roomNumber,
		},
		success:function(result){
			
			stus = JSON.parse(result)
		
			var stu = "";
			for(var i = 0; i < stus.length; i++ ){
				
				stu +="<tr>";
				stu +="<td>房间号</td><td><input type='text' class='form-control' id='roomNumber2' value='"+stus[i].roomnum+"' readonly='readonly'></td>";
				stu +="<td>房型</td><td><input type='text' class='form-control' id='roomType' value='"+stus[i].type+"' readonly='readonly'></td>";
				stu +="<td>价格</td><td><input type='text' class='form-control' id='roomPrice' value='"+stus[i].price+"' readonly='readonly'></td>";
				stu +="</tr>";
				stu +="<tr>";
				stu +="<td>入住人数</td><td><input type='text' class='form-control' id='roomPeople' value='"+stus[i].reserved3+"' readonly='readonly'></td>";
				stu +="</tr>";
				
				orderNumber = stus[i].reserved1;
			}
			
			$("#roomTable2").html(stu);
			nonmemberInf(orderNumber);

		},
		error:function(){
			alert("系统故障")
		}
	})	
}

//非会员获取信息-----模态框
function nonmemberInf(orderNumber){
	$.ajax({
		type:"post",
		url:"nonmemberInf.do",
		data:{
			"orderNumber":orderNumber,
		},
		success:function(result){
			
			stus = JSON.parse(result)
			var stu = "";
			for(var i = 0; i < stus.length; i++ ){
				
				stu +="<tr>";
				stu +="<td>姓名</td><td><input type='text' class='form-control' id='vipName' value='"+stus[i].name+"' readonly='readonly'></td>";
				stu +="<td>卡号</td><td><input type='text' class='form-control' id='vipNumber' value='非会员' readonly='readonly'></td>";
				stu +="</tr>";
				stu +="<tr>";
				stu +="<td>身份证</td><td><input type='text' class='form-control' id='vipIdnumber' value='"+stus[i].idnumber+"' readonly='readonly'></td>";
				stu +="<td>居住地址</td><td><input type='text' class='form-control' id='vipPhone' value='"+stus[i].address+"' readonly='readonly'></td>";
				stu +="</tr>";	
				
			}
			$("#vipTable").html(stu);
		},
		error:function(){
			alert("系统故障")
		}
	})
}

//获取vip信息-----模态框
function VipInf(vipnumber){
	$.ajax({
		type:"post",
		url:"checkoutInf.do",
		data:{
			"vipnumber":vipnumber,
		},
		success:function(result){
			
			stus = JSON.parse(result)
			var stu = "";
			for(var i = 0; i < stus.length; i++ ){
				
				stu +="<tr>";
				stu +="<td>姓名</td><td><input type='text' class='form-control' id='vipName' value='"+stus[i].name+"' readonly='readonly'></td>";
				stu +="<td>卡号</td><td><input type='text' class='form-control' id='vipNumber' value='"+stus[i].number+"' readonly='readonly'></td>";
				stu +="</tr>";
				stu +="<tr>";
				stu +="<td>身份证</td><td><input type='text' class='form-control' id='vipIdnumber' value='"+stus[i].idnumber+"' readonly='readonly'></td>";
				stu +="<td>电话号码</td><td><input type='text' class='form-control' id='vipPhone' value='"+stus[i].phone+"' readonly='readonly'></td>";
				stu +="</tr>";	
				
			}
			$("#vipTable").html(stu);
		},
		error:function(){
			alert("系统故障")
		}
	})
}

//退房
function checkOut(){
	
	var roomNumber = $("#roomNumber2").val();
	
	
	$.ajax({
		type:"post",
		url:"checkOut.do",
		data:{
			"roomNumber":roomNumber,
			
		},
		dataType:"text",
		success:function(result){
			if(result == "1"){
				alert("退房成功")
				$("#"+roomNumber+"").remove();
			}else{
				alert("退房失败")
			}
		},
		error:function(){
			alert("系统故障")
		}
	})
}

//刷新
function refresh(){
	window.location.href="queryRoom2.do"
}

</script>

<body>

<h3 align="center">退房办理</h3>

<table >
<tr><td><input type="text" name="roomNumber" id="roomNumber" class="form-control" placeholder="请输入房间号" value=""></td>
<td>&nbsp;&nbsp;<button class="btn btn-primary" onclick="selectRoomByNumber()">查询</button>&nbsp;&nbsp; </td>
</tr>
</table>
  <br>
<div>

		<table>
			<tr>
			<td>选择楼层：</td>	
				<td>
                <select name="floor" id="floor" class="form-control">

						<option value="0">默认</option>
						<c:forEach items="${floorlist}" var="floorlist">

						<option value="1">${floorlist.floor}</option>
						</c:forEach>

				</select>
				</td>
				<td>选择房型：</td>	
					<td>&nbsp;&nbsp;
				<select name="houseType" id="houseType" class="form-control">
				
				  <option value="0">默认</option>
				  
				  <c:forEach items="${houselist}" var="list">
	              <option value="0">${list.housetype}</option>
	              </c:forEach>
	           </select><br> 
				</td>
				
				<td>&nbsp;&nbsp;<button class="btn btn-primary" onclick="selectRoomByother()">查询</button>&nbsp;&nbsp; </td>
				<td><button type='button' onclick='refresh()' class='btn btn-success' >刷新</button></td>
				
			</tr>
		</table>
		  
    
</div><br>

	<table class="table table-hover" id="roomTable">

		<tr>
			<th>房间号</th>
			<th>楼层</th>
			<th>价格</th>
			<th>房型</th>
			<th>状态</th>
			<th>容纳人数</th>
			<th>入住人数</th>
			<th>备注</th>
			<th>操作</th>
		</tr>
		<c:forEach items="${pageInfo.list}" var="roomlist">

			<tr id="${roomlist.roomnum}">
				<td>${roomlist.roomnum}</td>
				<td>${roomlist.floor}</td>
				<td>${roomlist.price}</td>
				<td>${roomlist.type}</td>
				<td>${roomlist.status}</td>
				<td>${roomlist.quantity}</td>
				<td>${roomlist.reserved3}</td>
				<td>${roomlist.remark}</td>

				<c:choose>
					<c:when test="${roomlist.reserved2 == '非会员'}">
				<td>
				<button type="button" onclick="nonmemberCheckoutInf('${roomlist.roomnum}')" class="btn btn-success" data-toggle="modal" data-target="#checkoutModal">退房</button>
			    </td>
					</c:when>
					<c:otherwise>
				<td>
				<button type="button" onclick="checkoutInf('${roomlist.roomnum}')" class="btn btn-success" data-toggle="modal" data-target="#checkoutModal">退房</button>
			    </td>
					</c:otherwise>
				</c:choose>			
			</tr>

		</c:forEach>
	</table>

	<c:if test="${inf eq null}">
		<div id="page1">
	<c:if test="${!pageInfo.isFirstPage && !empty pageInfo}">
					<a href="${pageContext.request.contextPath }/queryRoom2.do">首页</a>
					<a href="${pageContext.request.contextPath }/queryRoom2.do?pageNum=${pageInfo.prePage}">上一页</a>
				</c:if>
				<c:if test="${!pageInfo.isLastPage }">
				<a href="${pageContext.request.contextPath }/queryRoom2.do?pageNum=${pageInfo.nextPage}">下一页</a>
				<a href="${pageContext.request.contextPath }/queryRoom2.do?pageNum=${pageInfo.lastPage}">末页</a>
				</c:if>
				当前页：${pageInfo.pageNum }/${pageInfo.pages }.
				</div>
				</c:if>
				
			<c:if test="${!(inf eq null)}">
		<div id="page1">
	<c:if test="${!pageInfo.isFirstPage && !empty pageInfo}">
					<a href="${pageContext.request.contextPath }/selectRoomByother2.do?floor=${floor}&state=${state}&houseType=${houseType}">首页</a>
					<a href="${pageContext.request.contextPath }/selectRoomByother2.do?pageNum=${pageInfo.prePage}&floor=${floor}&state=${state}&houseType=${houseType}">上一页</a>
				</c:if>
				<c:if test="${!pageInfo.isLastPage }">
				<a href="${pageContext.request.contextPath }/selectRoomByother2.do?pageNum=${pageInfo.nextPage}&floor=${floor}&state=${state}&houseType=${houseType}">下一页</a>
				<a href="${pageContext.request.contextPath }/selectRoomByother2.do?pageNum=${pageInfo.lastPage}&floor=${floor}&state=${state}&houseType=${houseType}">末页</a>
				</c:if>
				当前页：${pageInfo.pageNum }/${pageInfo.pages }.
				</div>
				</c:if>
				
				
				<!-- 退房模态框（Modal） -->
		<div class="modal fade" id="checkoutModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h3 class="modal-title" id="myModalLabel" align="center">
							退房办理
						</h3>
					</div>
					<div class="modal-body" >
							<table class="table table-bordered" id="roomTable2">
						
                            </table>
					</div>
					<div class="modal-footer" id="">
					
					<table class="table table-bordered" id="vipTable"></table>
					<button type='button' onclick='checkOut()' class='btn btn-success' >退房</button>
					</div>
					
				</div><!-- /.modal-content -->
			</div><!-- /.modal -->
		</div>	
				
	

</body>
</html>